package com.bwie.coupon.controller;

import com.bwie.common.core.domain.PageResult;
import com.bwie.common.core.domain.Result;
import com.bwie.coupon.domain.dto.CouponPlatformDTO;
import com.bwie.coupon.domain.vo.CouponPlatformVO;
import com.bwie.coupon.service.ICouponPlatformService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/platform")
@RestController
@Log4j2
public class CouponPlatformController {
    @Autowired
    private ICouponPlatformService couponPlatformService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 平台端
     * 获取待审核优惠券列表
     * @param couponPlatformDTO
     * @return
     */
    @PostMapping("/list")
    public Result<PageResult<CouponPlatformVO>> getCouponPlatformList(@RequestBody CouponPlatformDTO couponPlatformDTO){
        log.info("功能名称：获取待审核优惠券列表，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),couponPlatformDTO);
        PageResult<CouponPlatformVO> pageResult = couponPlatformService.selectCouponPlatformList(couponPlatformDTO);
        Result<PageResult<CouponPlatformVO>> result = Result.success(pageResult);
        log.info("功能名称：获取待审核优惠券列表，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 平台端
     * 根据优惠券id查看未审核优惠券详情
     * @param couponId
     * @return
     */
    @GetMapping("/couponDetails/{couponId}")
    public Result getCouponDetails(@PathVariable Long couponId){
        log.info("功能名称：根据优惠券id查看未审核优惠券详情，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),couponId);
        CouponPlatformVO couponDetails = couponPlatformService.getCouponDetails(couponId);
        Result<CouponPlatformVO> result = Result.success(couponDetails);
        log.info("功能名称：根据优惠券id查看未审核优惠券详情，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 平台端
     * 根据优惠券id修改审核状态
     * @param couponId
     * @param reviewStatus
     * @return
     */
    @PutMapping("/couponAudit/{couponId}/{reviewStatus}")
    public Result couponAudit(@PathVariable Long couponId,@PathVariable Integer reviewStatus){
        log.info("功能名称：根据优惠券id修改审核状态，请求url：{}，请求方式：{}，请求参数：{}、{}",request.getRequestURI(),request.getMethod(),couponId,reviewStatus);
        couponPlatformService.couponAudit(couponId,reviewStatus);
        Result<Object> result = Result.success();
        log.info("功能名称：根据优惠券id修改审核状态，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }
}
